home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / promode3.zip / TERMINAL.C < prev    next >
C/C++ Source or Header  |  1993-01-06  |  2KB  |  78 lines

  1. /*
  2.  
  3. TERMINAL.C
  4.  
  5. This is a sample TERMINAL program that you can use as a building block..
  6.  
  7.                     Adrian J. Michaud
  8. */
  9.  
  10. #include "string.h"
  11. #include "stdio.h"
  12. #include "conio.h"
  13. #include "promodem.h"
  14.  
  15. void main(void);
  16. void main(void)
  17. {
  18. char ch;
  19. AJMS cb1;
  20. unsigned int irq=0, base_address=0;
  21. char com_port[255];
  22.  
  23. while (!irq && !base_address)
  24.   {
  25.   printf("\nEnter Com port [1 or 2]: ");
  26.   gets(com_port);
  27.  
  28.   if (strstr(com_port, "1"))
  29.      {
  30.      base_address = 0x3f8;
  31.      irq          = 4;
  32.      }
  33.  
  34.   else
  35.   if (strstr(com_port, "2"))
  36.      {
  37.      base_address = 0x2f8;
  38.      irq          = 3;
  39.      }
  40.   }
  41.  
  42. #define BUFFER_SIZE 4096  /* Use a 4K IRQ Buffer */
  43.  
  44. SetupControlBlock(&cb1 , base_address , irq , BUFFER_SIZE);
  45.  
  46. OpenCom(&cb1);              /* Open Com Port                               */
  47. SetBaudRate(&cb1, 38400L);  /*  38.4k Baud.. Use 2400 for 2400 baud modems */
  48. SetDataFormat(&cb1, BITS_8|NO_PARITY|STOP_BITS_1); /*  8-N-1               */
  49.  
  50. if (SetFIFOMode(&cb1) == FIFO_ENABLED)              /* Enable 16550 if any */
  51.    {
  52.    SetFIFOTriggerLevel(&cb1, FIFO_16_TRIGGER); /* Turn on 16 byte RCVR FIFO */
  53.    printf("\nUART is a 16550! FIFO's Enabled.\n");
  54.    }
  55. else printf("\nUART is a 16540 or 8250.\n");
  56.  
  57. printf("\nLoad ANSI.SYS if you wish to display ANSI.\n");
  58. printf("\nPress [ESC] to Exit this Sample Terminal Program..\n");
  59.  
  60. printf("\nUse Hayes AT Commands to Talk to your modem.  If you don't get a");
  61. printf("\nresponse, try the other COM port, or change your IRQ setting.\n");
  62.  
  63. for ( ; ; ) /* Mini Terminal Program.. (REQUIRES ANSI.SYS loaded for ansi) */
  64.    {
  65.    if (kbhit())                              /* Check if Key Press */
  66.      {
  67.      ch = (char)getch();                     /* Get Character from Keyboard */
  68.      if (ch == 27) break;                    /* if ESC, ABORT!              */
  69.      SendCharacter(&cb1, (unsigned char)ch); /* Send character to modem     */
  70.      }
  71.    if (CheckQueue(&cb1)==CHARACTERS_WAITING)  /* Check IRQ buffer for chars */
  72.       printf("%c", (unsigned char)GetCharacter(&cb1)); /* Display Them */
  73.    }
  74. CloseCom(&cb1);
  75. DropDTR(&cb1);   /* Disable Data Terminal Ready */
  76. }
  77.  
  78.